﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    /// 工作组BLL
    /// </summary>
    public class HRWorkGrp
    {
        /// <summary>
        /// 工作组DAL
        /// </summary>
        private readonly DAL.HRWorkGrp dal = new DAL.HRWorkGrp();
        /// <summary>
        /// 构造方法
        /// </summary>
        public HRWorkGrp()
        { }
        /// <summary>
        /// 获得数据列表
        ///<creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="strWhere">SQL判断条件</param>
        /// <returns>数据列表</returns>
        public List<Model.HRWorkGrp> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 删除工作组（事务处理）
        ///<creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="fEntityNo">组织机构编号</param>
        /// <param name="fWorkGrpNo">工作组编号</param>
        public void DeleteWorkGroupAndDuty(string fEntityNo, string fWorkGrpNo)
        {
            dal.DeleteWorkGroupAndDuty(fEntityNo, fWorkGrpNo);
        }

        /// <summary>
        /// 修改工作组（事务处理）
        ///<creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="model">工作组信息</param>
        /// <param name="dutys">增加的职位列表</param>
        public void UpdateWorkGroupAndDuty(Model.HRWorkGrp model, List<Model.HRWorkGrpDuty> dutys)
        {
            dal.UpdateWorkGroupAndDuty(model, dutys);
        }

        /// <summary>
        /// 增加工作组（事务处理）
        ///<creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="model">工作组信息</param>
        /// <param name="dutys">增加的职位列表</param>
        public void AddWorkGroupAndDuty(Model.HRWorkGrp model, List<Model.HRWorkGrpDuty> dutys)
        {
            dal.AddWorkGroupAndDuty(model, dutys);
        }

        /// <summary>
        /// 得到一个实体对象
        ///<creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="fEntityNo">组织机构编号</param>
        /// <param name="fWorkGrpNo">工作组编号</param>
        /// <returns>工作组信息</returns>
        public Model.HRWorkGrp GetModel(string fEntityNo, string fWorkGrpNo)
        {

            return dal.GetModel(fEntityNo, fWorkGrpNo);
        }
        /// <summary>
        /// 根据公司编号获取数据列表
        /// <creator>wangl</creator>
        /// <date>2013-07-29</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns>DataSet对象</returns>
        public List<Model.HRWorkGrp> GetListByEntityNo(string entityNo)
        {
            DataSet ds = dal.GetListByEntityNo(entityNo);
            return DataTableToList(ds.Tables[0]);
        }

        /// <summary>
        /// 获取数据列表
        ///<creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="dt">需转换数据源</param>
        /// <returns>转换后数据列表</returns>
        public List<Model.HRWorkGrp> DataTableToList(DataTable dt)
        {
            List<Model.HRWorkGrp> modelList = new List<Model.HRWorkGrp>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.HRWorkGrp model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.HRWorkGrp();
                    model.FEntityNo = dt.Rows[n]["FEntityNo"].ToString();
                    model.FWorkGrpNo = dt.Rows[n]["FWorkGrpNo"].ToString();
                    model.FWorkGrpName = dt.Rows[n]["FWorkGrpName"].ToString();
                    model.FIsUse = dt.Rows[n]["FIsUse"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

    }
}
